import time

from common.base import Base, open_browser

login_url = "http://ecshop.itsoso.cn/user.php"


class LoginPage(Base):
    """表现层"""
    username_loc = ("name", "username")  # 用户名输入框
    password_loc = ("name", "password")  # 密码输入框
    submit_loc = ("name", "submit")  # 立即登录按钮
    remember_loc = ("id", "remember")  # 记住密码
    mm_question_loc = ("link text", "密码问题")  # 密码问题
    email_loc = ("link text", "邮件")  # 邮件
    massage_loc = ("link text", "短信验证")  # 短信验证
    register_loc = ("css selector", "div.usTxt>a>img")  # 立即注册按钮
    home_page_loc = ("link text", "首页")  # 首页

    """操作层"""

    def input_username(self, text):
        """输入用户名"""
        self.send_keys(self.username_loc, text)
        time.sleep(1)

    def input_password(self, text):
        """输入密码"""
        self.send_keys(self.password_loc, text)
        time.sleep(1)

    def click_submit(self):
        """点击立即登录"""
        self.click(self.submit_loc)
        time.sleep(3)

    def click_remember(self):
        """点击记住密码"""
        self.click(self.remember_loc)
        time.sleep(2)

    def click_password_question(self):
        """点击密码找回密码问题"""
        self.click(self.mm_question_loc)
        time.sleep(2)

    def click_email(self):
        """点击密码找回邮件"""
        self.click(self.email_loc)
        time.sleep(3)

    def click_massage(self):
        """点击短信验证"""
        self.click(self.massage_loc)
        time.sleep(3)

    def click_register(self):
        """点击立即注册"""
        self.click(self.register_loc)
        time.sleep(3)

    def click_home_page(self):
        """点击首页"""
        self.click(self.home_page_loc)
        time.sleep(3)


if __name__ == '__main__':
    driver = open_browser()
    login = LoginPage(driver)
    login.open_url(login_url)
    login.input_username("yangjun")
    login.input_password("123456")
    login.click_submit()
    time.sleep(5)
    login.close_browser()
